﻿using System.IO;

namespace SharpTag.ID3
{
    /// <summary>
    /// Concreate implementation of the <see cref="AbstractFileFactory"/> class.
    /// </summary>
    public class FileFactory : AbstractFileFactory
    {
        /// <summary>
        /// Creates a new MP3 <see cref="ITaggedFile"/> object.
        /// </summary>
        /// <param name="filePath">The full path of the MP3 File.</param>
        /// <returns>An <see cref="ITaggedFile"/> object.</returns>
        public override ITaggedFile CreateMP3File(string filePath)
        {
            if (!File.Exists(filePath)) return null;

            return CreateFile(filePath);
        }

        /// <summary>
        /// Creates a new <see cref="ITaggedFile"/> object.
        /// </summary>
        /// <param name="filePath">The full path of the file.</param>
        /// <returns>An <see cref="ITaggedFile"/> object.</returns>
        private ITaggedFile CreateFile(string filePath)
        {
            FileInfo fInfo = new FileInfo(filePath);
            var ext = fInfo.Extension.Remove(0,1).ToLower();

            switch (ext)
            {
                case "mp3":
                    return new MP3File(filePath);
            }

            return null;
        }
    }
}
